/**
 * Created by oneminute on 8/17/14.
 */

var fs = require("fs");
var lz = require("../lib/utils/modules")();
var moment = require("moment");

var file = fs.readFile("predev/json.txt", { encoding: 'utf-8'}, function (_err, _data) {
    //lz.Logger.debug(_err);
    //lz.Logger.debug(_data);
    var json = JSON.parse(_data);
    //lz.Logger.debug(json);
    json.array.sort(function (_a, _b) {
        //return _b.publishDate.localeCompare(_a);
        var d = _a.distance - _b.distance;
        //lz.Logger.debug(d);
        if (d != 0) {
            return d;
        } else {
            //return _b.publishDate.localeCompare(_a);
            var ta = moment(_a.publishDate, lz.Config.datetimeFormat);
            var tb = moment(_b.publishDate, lz.Config.datetimeFormat);
            /*lz.Logger.debug("比较");
            lz.Logger.debug(ta.toString(), tb.toString());
            lz.Logger.debug(ta.isBefore(tb));*/
            if (ta.isAfter(tb)) {
                return -1;
            } else {
                return 1;
            }
        }
    });
    json.array.forEach(function (_item) {
        lz.Logger.debug("%s %d %s", _item.name, _item.distance, _item.publishDate);
    });
});
